//
//  growthPhotosVController.m
//  SKaURobot
//
//  Created by cdong on 16/2/26.
//  Copyright © 2016年 cdong. All rights reserved.
//

#import "growthPhotosVController.h"
#import "growthPhotosView.h"
#import "growthLeftTVController.h"
#import "growthRightVController.h"

@interface growthPhotosVController ()<UIScrollViewDelegate>

@property (nonatomic ,strong)growthPhotosView *growthView;

@end

@implementation growthPhotosVController

- (void)loadView{
    self.growthView = [[growthPhotosView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    self.view = self.growthView;
}

- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

// 返回首页
- (void)backBtnAction:(UIButton *)sender{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBarHidden = YES;
    [self.growthView.backBtn addTarget:self action:@selector(backBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.growthView.growthLeftBtn addTarget:self action:@selector(growthLeftBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.growthView.growthRightBtn addTarget:self action:@selector(growthRightBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    self.growthView.contentScrollV.pagingEnabled= YES;
    self.growthView.contentScrollV.delegate = self;
    growthLeftTVController *leftVC = [[growthLeftTVController alloc]init];
    [self addChildViewController:leftVC];
    [self.growthView.leftView addSubview:leftVC.view];
    growthRightVController *rightVC = [[growthRightVController alloc]init];
    [self addChildViewController:rightVC];
    [self.growthView.rightView addSubview:rightVC.view];
}

// 左边成长相册按钮
- (void)growthLeftBtnAction:(UIButton *)sender{
    [self.growthView.growthLeftBtn setTitleColor:[RGBColorEncapsulation colorWithRGB:0xffffff alpha:1] forState:UIControlStateNormal];
    [self.growthView.growthRightBtn setTitleColor:[RGBColorEncapsulation colorWithRGB:0x7e7e7d alpha:1] forState:UIControlStateNormal];
    [UIView animateWithDuration:0.25 animations:^{
        self.growthView.contentScrollV.contentOffset = CGPointMake(0 * self.view.frame.size.width, 0);
        self.growthView.fillV.frame = CGRectMake(CGRectGetMinX(self.growthView.growthLeftBtn.frame), self.growthView.fillV.frame.origin.y, self.growthView.fillV.frame.size.width, self.growthView.fillV.frame.size.height);
    } completion:^(BOOL finished) {
        
    }];
}

// 右边更多照片按钮
- (void)growthRightBtnAction:(UIButton *)sender{
    
    [self.growthView.growthRightBtn setTitleColor:[RGBColorEncapsulation colorWithRGB:0xffffff alpha:1] forState:UIControlStateNormal];
    [self.growthView.growthLeftBtn setTitleColor:[RGBColorEncapsulation colorWithRGB:0x7e7e7d alpha:1] forState:UIControlStateNormal];
    [UIView animateWithDuration:0.25 animations:^{
        self.growthView.contentScrollV.contentOffset = CGPointMake(1 * self.view.frame.size.width, 0);
        self.growthView.fillV.frame = CGRectMake(CGRectGetMinX(self.growthView.growthRightBtn.frame), self.growthView.fillV.frame.origin.y, self.growthView.fillV.frame.size.width, self.growthView.fillV.frame.size.height);
    } completion:^(BOOL finished) {
    
    }];
}

/*
 滚动滑条
 */
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    float x = self.growthView.contentScrollV.contentOffset.x;
    [UIView animateWithDuration:0.1 animations:^{
        self.growthView.fillV.frame = CGRectMake(x/2,self.growthView.fillV.frame.origin.y, self.growthView.fillV.frame.size.width, self.growthView.fillV.frame.size.height);
    } completion:^(BOOL finished) {
        if (self.growthView.fillV.frame.origin.x < self.view.frame.size.width/2) {
            [self.growthView.growthLeftBtn setTitleColor:[RGBColorEncapsulation colorWithRGB:0xffffff alpha:1] forState:UIControlStateNormal];
            [self.growthView.growthRightBtn setTitleColor:[RGBColorEncapsulation colorWithRGB:0x7e7e7d alpha:1] forState:UIControlStateNormal];
        }else {
            [self.growthView.growthRightBtn setTitleColor:[RGBColorEncapsulation colorWithRGB:0xffffff alpha:1] forState:UIControlStateNormal];
            [self.growthView.growthLeftBtn setTitleColor:[RGBColorEncapsulation colorWithRGB:0x7e7e7d alpha:1] forState:UIControlStateNormal];
        }
    }];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    float x = self.growthView.contentScrollV.contentOffset.x;
    [UIView animateWithDuration:0.1 animations:^{
        self.growthView.fillV.frame = CGRectMake(x/2,self.growthView.fillV.frame.origin.y, self.growthView.fillV.frame.size.width, self.growthView.fillV.frame.size.height);
    } completion:^(BOOL finished) {
        if (self.growthView.fillV.frame.origin.x < self.view.frame.size.width/2) {
            [self.growthView.growthLeftBtn setTitleColor:[RGBColorEncapsulation colorWithRGB:0xffffff alpha:1] forState:UIControlStateNormal];
            [self.growthView.growthRightBtn setTitleColor:[RGBColorEncapsulation colorWithRGB:0x7e7e7d alpha:1] forState:UIControlStateNormal];
        }else {
            [self.growthView.growthRightBtn setTitleColor:[RGBColorEncapsulation colorWithRGB:0xffffff alpha:1] forState:UIControlStateNormal];
            [self.growthView.growthLeftBtn setTitleColor:[RGBColorEncapsulation colorWithRGB:0x7e7e7d alpha:1] forState:UIControlStateNormal];
        }
    }];
}

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
    float x = self.growthView.contentScrollV.contentOffset.x;
    [UIView animateWithDuration:0.1 animations:^{
        self.growthView.fillV.frame = CGRectMake(x/2,self.growthView.fillV.frame.origin.y, self.growthView.fillV.frame.size.width, self.growthView.fillV.frame.size.height);
    } completion:^(BOOL finished) {
        if (self.growthView.fillV.frame.origin.x < self.view.frame.size.width/2) {
            [self.growthView.growthLeftBtn setTitleColor:[RGBColorEncapsulation colorWithRGB:0xffffff alpha:1] forState:UIControlStateNormal];
            [self.growthView.growthRightBtn setTitleColor:[RGBColorEncapsulation colorWithRGB:0x7e7e7d alpha:1] forState:UIControlStateNormal];
        }else {
            [self.growthView.growthRightBtn setTitleColor:[RGBColorEncapsulation colorWithRGB:0xffffff alpha:1] forState:UIControlStateNormal];
            [self.growthView.growthLeftBtn setTitleColor:[RGBColorEncapsulation colorWithRGB:0x7e7e7d alpha:1] forState:UIControlStateNormal];
        }
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
